package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.twins.log.CrossTwinsPvpBattleLog;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogCrossTwinsLogDaoImpl extends TempDao {

    public boolean addLogTwinsPvpBattleList(List<CrossTwinsPvpBattleLog> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getCross2Db());
        String sql = "INSERT INTO " +
                " t_l_activity_twins_pvp_attack(activityId,groupId,userId,bossId,attackUserId,attackValue,prestige,allPrestige,isKill,selfValue,time) " +
                " VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (CrossTwinsPvpBattleLog data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGroupId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBossId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getAttackUserId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getAttackValue()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getPrestige()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getAllPrestige()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getIsKill()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getSelfValue()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

}
